package com.ims.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ims.dao.RoleMapper;
import com.ims.pojo.Role;
import com.ims.service.RoleService;
import com.ims.util.Result;
import com.ims.util.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yekka1
 * @description: TODO
 * @date 2022/9/9 15:47
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Autowired
    private RoleService roleService;

    /**
     * 查询所有角色
     * @return
     */
    @Override
    public Result<List<Role>> findAll() {
        LambdaQueryWrapper<Role> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Role::getStatus,"1");
        lambdaQueryWrapper.orderByAsc(Role::getCreateTime);
        List<Role> roleList = roleService.list(lambdaQueryWrapper);
        return new Result<>(true, StatusCode.OK, "查询所有角色成功", roleList);
    }

    /**
     *查询所有角色（不包括超级管理员）
     * @return
     */
    @Override
    public Result<List<Role>> findWithOutSuper() {
        LambdaQueryWrapper<Role> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Role::getStatus,"1");
        lambdaQueryWrapper.ne(Role::getRoleKey,"super_admin");
        List<Role> roleList = roleService.list(lambdaQueryWrapper);
        return new Result<>(true, StatusCode.OK, "查询所有角色成功", roleList);
    }
}
